



package jnpf.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jnpf.annotation.JnpfField;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.base.UserInfo;
import jnpf.base.vo.DownloadVO;
import jnpf.config.ConfigValueUtil;
import jnpf.exception.DataException;
import jnpf.onlinedev.model.ExcelImFieldModel;
import jnpf.onlinedev.model.OnlineImport.ExcelImportModel;
import jnpf.onlinedev.model.OnlineImport.VisualImportModel;
import jnpf.permission.entity.UserEntity;
import org.springframework.transaction.annotation.Transactional;
import jnpf.base.entity.ProvinceEntity;
import jnpf.model.mzotherconfiguration.*;
import jnpf.model.mzotherconfiguration.MzOtherconfigurationPagination;
import jnpf.entity.*;
import jnpf.util.*;
import jnpf.base.util.*;
import jnpf.base.vo.ListVO;
import jnpf.util.context.SpringContext;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import lombok.Cleanup;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jnpf.entity.MzOtherconfigurationEntity;
import jnpf.service.MzOtherconfigurationService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import jnpf.util.GeneraterSwapUtil;
import java.util.stream.Collectors;
import java.util.*;

import cn.xuyanwu.spring.file.storage.FileInfo;


/**
 *
 * mzOtherconfiguration
 * @版本： V3.2.0
 * @版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * @作者： JNPF开发平台组
 * @日期： 2023-12-08
 */
@Slf4j
@RestController
@Tag(name = "mzOtherconfiguration" , description = "example")
@RequestMapping("/api/example/MzOtherconfiguration")
public class MzOtherconfigurationController {

    @Autowired
    private GeneraterSwapUtil generaterSwapUtil;


    @Autowired
    private UserProvider userProvider;


    @Autowired
    private MzOtherconfigurationService mzOtherconfigurationService;



    /**
     * 列表
     *
     * @param mzOtherconfigurationPagination
     * @return
     */
    @Operation(summary = "获取列表")
	@PostMapping("/getList")
    public ActionResult list(@RequestBody MzOtherconfigurationPagination mzOtherconfigurationPagination)throws IOException{
    //树形判断是否有参数，有参数不造树
        List<MzOtherconfigurationEntity> list= mzOtherconfigurationService.getList(mzOtherconfigurationPagination);
        //处理id字段转名称，若无需转或者为空可删除

    List<MzOtherconfigurationListVO> listVO=JsonUtil.getJsonToList(list,MzOtherconfigurationListVO.class);
    for(MzOtherconfigurationListVO mzOtherconfigurationVO:listVO){
        ActionResult info = info(mzOtherconfigurationVO.getId());
        Map<String, Object> dataMap = JsonUtil.entityToMap(info.getData());
                mzOtherconfigurationVO.setIsapprove_name(generaterSwapUtil.switchSelectValue(mzOtherconfigurationVO.getIsapprove() ,"开" ,"关"));

            mzOtherconfigurationVO.setApprovaltype_name(generaterSwapUtil.getDicName(mzOtherconfigurationVO.getApprovaltype(),"502831756479561733"));

            mzOtherconfigurationVO.setStoragetype_name(generaterSwapUtil.getDicName(mzOtherconfigurationVO.getStoragetype(),"502832130410151941"));

                mzOtherconfigurationVO.setWatermarkurl_name(generaterSwapUtil.getFileNameInJson(mzOtherconfigurationVO.getWatermarkurl()));

		//子表数据转换
     }

         PageListVO vo=new PageListVO();
         vo.setList(listVO);
         PaginationVO page=JsonUtil.getJsonToBean(mzOtherconfigurationPagination,PaginationVO.class);
         vo.setPagination(page);
         return ActionResult.success(vo);

    }

    /**
     * 创建
     *
     * @param mzOtherconfigurationForm
     * @return
     */
    @PostMapping
    @Transactional
    @Operation(summary = "创建")
    public ActionResult create(@RequestBody @Valid MzOtherconfigurationForm mzOtherconfigurationForm) throws DataException {
        String b = mzOtherconfigurationService.checkForm(mzOtherconfigurationForm,0);
        if (StringUtil.isNotEmpty(b)){
         return ActionResult.fail(b + "不能重复");
        }
        String mainId =RandomUtil.uuId();

        UserInfo userInfo=userProvider.get();
		UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId());
        GeneraterSwapUtil.swapDatetime(mzOtherconfigurationForm);
        MzOtherconfigurationEntity entity = JsonUtil.getJsonToBean(mzOtherconfigurationForm, MzOtherconfigurationEntity.class);
            entity.setId(mainId);
                mzOtherconfigurationService.save(entity);


        return ActionResult.success("创建成功");
}


    /**
    * 信息
    *
    * @param id
    * @return
    */
    @Operation(summary = "信息")
    @GetMapping("/{id}")
    public ActionResult<MzOtherconfigurationInfoVO> info(@PathVariable("id") String id){
        MzOtherconfigurationEntity entity= mzOtherconfigurationService.getInfo(id);
        MzOtherconfigurationInfoVO vo=JsonUtil.getJsonToBean(entity, MzOtherconfigurationInfoVO.class);

    //子表
    //副表
        return ActionResult.success(vo);
    }

    /**
    * 表单信息(详情页)
    *
    * @param id
    * @return
    */
    @Operation(summary = "表单信息(详情页)")
    @GetMapping("/detail/{id}")
    public ActionResult<MzOtherconfigurationInfoVO> detailInfo(@PathVariable("id") String id){
        ActionResult info = info(id);
        Map<String,Object> dataMap = JsonUtil.entityToMap(info.getData());
        MzOtherconfigurationEntity entity= mzOtherconfigurationService.getInfo(id);
        MzOtherconfigurationInfoVO vo=JsonUtil.getJsonToBean(entity, MzOtherconfigurationInfoVO.class);

 //子表数据转换

 //附表数据转换

//添加到详情表单对象中
                vo.setIsapprove(generaterSwapUtil.switchSelectValue(vo.getIsapprove() ,"开" ,"关"));

            vo.setApprovaltype(generaterSwapUtil.getDicName(vo.getApprovaltype(),"502831756479561733"));

            vo.setStoragetype(generaterSwapUtil.getDicName(vo.getStoragetype(),"502832130410151941"));

                vo.setWatermarkurl(generaterSwapUtil.getFileNameInJson(vo.getWatermarkurl()));


        return ActionResult.success(vo);
		}




   /**
    * 更新
    *
    * @param id
    * @param mzOtherconfigurationForm
    * @return
    */
    @PutMapping("/{id}")
    @Transactional
    @Operation(summary = "更新")
    public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid MzOtherconfigurationForm mzOtherconfigurationForm) throws DataException {
        String b =  mzOtherconfigurationService.checkForm(mzOtherconfigurationForm,1);
        if (StringUtil.isNotEmpty(b)){
            return ActionResult.fail(b + "不能重复");
        }
        UserInfo userInfo=userProvider.get();
        MzOtherconfigurationEntity entity= mzOtherconfigurationService.getInfo(id);
        if(entity!=null){
            GeneraterSwapUtil.swapDatetime(mzOtherconfigurationForm);
            MzOtherconfigurationEntity subentity=JsonUtil.getJsonToBean(mzOtherconfigurationForm, MzOtherconfigurationEntity.class);
				boolean b1 = mzOtherconfigurationService.updateById(subentity);
				if (!b1){
				return ActionResult.fail("当前表单原数据已被调整，请重新进入该页面编辑并提交数据");
				}
        return ActionResult.success("更新成功");
        }else{
            return ActionResult.fail("更新失败，数据不存在");
        }
    }



   /**
    * 删除
    *
    * @param id
    * @return
    */
    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    @Transactional
    public ActionResult delete(@PathVariable("id") String id){
        MzOtherconfigurationEntity entity= mzOtherconfigurationService.getInfo(id);
        if(entity!=null){
            mzOtherconfigurationService.delete(entity);
        }
        return ActionResult.success("删除成功");
    }






}
